{include file="public/meta" /}
<link href="__LIB__/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<title>添加消息</title>
</head>
<body>
<article class="cl pd-20">
    <form class="form form-horizontal" id="form-member-add" method="post">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>消息类型：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
                    <select class="select" size="1" name="type" id="type">
                        <option value="0" selected>请选择分类</option>
                        <option value="1">系统消息</option>
                        <option value="2">业务消息</option>
                    </select>
                    </span> </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>消息标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="2-50个汉字组成" id="title" name="title">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>需要发送的用户：</label>
            <div style="margin-left: 80px;">
                <input type="radio" name="user" value="0" id="qunfa" checked>群发
                <input type="radio" name="user" value="1" id="yonghu">指定用户
            </div>
        </div>
        <div class="row cl" style="display: none;" id="msginfo">
            <label class="form-label col-xs-4 col-sm-3"></label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea name="mobile" id="mobile" class="textarea" placeholder="请输入用户的账号 每个用户之间用'|'分隔开 严格按照格式进行操作 例: 13071011080|18801338407|"></textarea><span color="#999"></span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>排序数字：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="0" placeholder="只能填写大于等于0的数字" id="sort" name="sort">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>消息内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea name="content" id="content" class="textarea"></textarea>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;确认添加&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
{include file="public/footer" /}
<!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $(function(){
        $('#qunfa').click(function(){
            $("#msginfo").hide();
        });
        $('#yonghu').click(function(){
            $("#msginfo").show();
        });
        if ($("#qunfa").checked == true) {
            $("#msginfo").hide();
        }
        if ($("#yonghu").checked == true) {
            $("#msginfo").show();
        }
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        $('.input-file').change(function(){
            var filess=$('.input-file')[0].files[0];
            console.log(filess);
            var fm=new FormData();
            fm.append('image',filess);

            $.ajax({
                type: 'post',
                url: '{:url("Common/uploadImage")}',
                data: fm,
                processData: false,
                contentType: false,
                success: function(data) {
                    var jdata=JSON.parse(data);
                    if(jdata.code==0)
                    {
                        parent.layer.msg(jdata.msg,{icon:6,time:1000});
                        var imgurl=jdata.data;
                        imgurl= imgurl.replace(/\\/g, "/");
                        $('#img_url').val(imgurl);
                    }
                    else
                    {
                        parent.layer.msg(jdata.msg,{icon:5,time:1000});
                    }

                },
                error:function(data){
                    layer.msg('500系统错误，请重试！',{icon:5,time:1000});
                }
            });

        });
        $("#form-member-add").validate({
            rules:{
                title:{
                    required:true,
                    minlength:2,
                    maxlength:16
                },
                description:{
                    required:true,
                    minlength:1,
                    maxlength:500
                },
                sort:{
                    required:true,
                    digits:true
                },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $.ajax({
                    type: 'post',
                    url: '{:url("System/messageAddSave")}',
                    data: {
                        'type' : $('#type option:selected').val(),
                        'title': $('#title').val(),
                        'user' : $("input[name='user']:checked").val(),
                        'sort' : $('#sort').val(),
                        'content' : $('#content').val(),
                        "mobile"  : $('#mobile').val()
                    },
                    dataType:'json',
                    success: function(data) {
                        if(data.code==0)
                        {
                            parent.layer.msg(data.msg,{icon:6,time:1000});
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.window.location.reload();
                            parent.layer.close(index);
                        }
                        else
                        {
                            parent.layer.msg(data.msg,{icon:5,time:1000});
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }

                    },
                    error:function(data){
                        layer.msg('500系统错误，请重试！',{icon:5,time:1000});
                    }
                });

            }
        });
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>